define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'work.attendance_statistics/index',
        add_url: 'work.attendance_statistics/add',
        edit_url: 'work.attendance_statistics/edit',
        delete_url: 'work.attendance_statistics/delete',
        export_url: 'work.attendance_statistics/export',
        modify_url: 'work.attendance_statistics/modify',
        recycle_url: 'work.attendance_statistics/recycle',
    };

    return {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ["refresh", "export"],
                cols: [[
                    { type: 'checkbox' },
                    { field: 'id', title: 'ID', width: 40, search: 'false' },
                    { field: 'statistics_date', title: '统计日期' , search: 'time'},
                    { field: 'work_days', title: '上班（天）', search: 'false' },
                    { field: 'rest_days', title: '休息（天）', search: 'false' },
                    { field: 'leave_days', title: '请假（天）', search: 'false' },
                    { field: 'drive_days', title: '驾驶（天）', search: 'false' },
                    { field: 'sum_duration', width: 160, title: '总计工时（天）', templet: '#work_duration', search: 'false' },
                    {
                        width: 250, title: '操作', templet: ea.table.tool,
                        operat: ["delete"]
                    },

                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        recycle: function () {
            init.index_url = init.recycle_url;
            ea.table.render({
                init: init,
                toolbar: ['refresh',
                    [{
                        class: 'layui-btn layui-btn-sm',
                        method: 'get',
                        field: 'id',
                        icon: 'fa fa-refresh',
                        text: '全部恢复',
                        title: '确定恢复？',
                        auth: 'recycle',
                        url: init.recycle_url + '?type=restore',
                        checkbox: true
                    }, {
                        class: 'layui-btn layui-btn-danger layui-btn-sm',
                        method: 'get',
                        field: 'id',
                        icon: 'fa fa-delete',
                        text: '彻底删除',
                        title: '确定彻底删除？',
                        auth: 'recycle',
                        url: init.recycle_url + '?type=delete',
                        checkbox: true
                    }], 'export',
                ],
                cols: [[
                    { type: 'checkbox' },
                    { field: 'id', title: 'ID' },
                    { field: 'statistics_date', title: '统计日期' },
                    { field: 'work_days', title: '上班天数' },
                    { field: 'rest_days', title: '休息天数' },
                    { field: 'leave_days', title: '请假天数' },
                    { field: 'sum_duration', title: '总计工时' },
                    { field: 'drive_days', title: '驾驶天数' },

                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                title: '确认恢复？',
                                text: '恢复数据',
                                filed: 'id',
                                url: init.recycle_url + '?type=restore',
                                method: 'get',
                                auth: 'recycle',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                            }, {
                                title: '想好了吗？',
                                text: '彻底删除',
                                filed: 'id',
                                method: 'get',
                                url: init.recycle_url + '?type=delete',
                                auth: 'recycle',
                                class: 'layui-btn layui-btn-xs layui-btn-normal layui-bg-red',
                            }]]
                    }
                ]],
            });

            ea.listen();
        },
    };
});